package cn.xinfei.xdecision.data.core.vo;

import cn.xinfei.xdecision.common.model.datax.enums.CollectStageEnum;
import cn.xinfei.xdecision.data.core.frame.executors.VarContext;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Data
public class VarCollectAwareVO implements VarContext<VarCollectAwareVO> {
    private String requestId;
    private JSONObject inputPrarams;
    private Map<String, List<String>> apiVariablesMap = Maps.newHashMap();
    private Set<String> varCodes = new HashSet<>();
    private List<String> chargedCodes = Lists.newArrayList();
    private CollectStageEnum collectStageEnum;
    private List<String> usedExecutorEnums = Lists.newArrayList();
    private Map<String, Integer> varCodeAndTypeMap = Maps.newHashMap();
    private Map<String, Set<String>> executorAndVarCodesMap = Maps.newHashMap();
    private Map<String, Set<String>> derivedVarDependParamMap = Maps.newHashMap();
    private Map<String, Object> executorResultMap = Maps.newHashMap();

    @Override
    public void setContext(VarCollectAwareVO varCollectAwareVO) {
        this.setRequestId(varCollectAwareVO.getRequestId());
        this.setInputPrarams(varCollectAwareVO.getInputPrarams());
        this.setApiVariablesMap(varCollectAwareVO.getApiVariablesMap());
        this.setVarCodes(varCollectAwareVO.getVarCodes());
        this.setCollectStageEnum(varCollectAwareVO.getCollectStageEnum());
        this.setUsedExecutorEnums(varCollectAwareVO.getUsedExecutorEnums());
        this.setVarCodeAndTypeMap(varCollectAwareVO.getVarCodeAndTypeMap());
        this.setExecutorAndVarCodesMap(varCollectAwareVO.getExecutorAndVarCodesMap());
        this.setExecutorResultMap(varCollectAwareVO.getExecutorResultMap());
        this.setDerivedVarDependParamMap(varCollectAwareVO.getDerivedVarDependParamMap());
    }

    @Override
    public VarCollectAwareVO get() {
        return this;
    }

    @Override
    public boolean isHandle() {
        return CollectionUtils.isNotEmpty(varCodes);
    }
}
